refactor(consts): extract hard-coded strings into constants#226
refactor(consts): extract hard-coded strings into constants#226
Conversation
Replace hard-coded 'stackone-ai-node' User-Agent string with a shared constant to improve maintainability and ensure consistency across the codebase. Changes: - Add USER_AGENT constant to src/consts.ts - Update requestBuilder.ts to use USER_AGENT constant - Update rpc-client.ts to use USER_AGENT constant - Update utils/errors.ts to use USER_AGENT constant - Update requestBuilder.test.ts to use USER_AGENT constant This centralises the User-Agent value, making future updates simpler and reducing the risk of inconsistent values across different modules.
commit: |
There was a problem hiding this comment.
Pull request overview
This PR refactors the User-Agent string by extracting the hard-coded 'stackone-ai-node' value into a shared USER_AGENT constant in src/consts.ts. This improves code maintainability by centralizing the value and reducing duplication across multiple files.
- Introduces
USER_AGENTconstant insrc/consts.tswith appropriate documentation - Replaces all hard-coded User-Agent string occurrences across production and test code
- Maintains consistent behavior while improving code organization
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/consts.ts | Defines new USER_AGENT constant with JSDoc comment |
| src/utils/errors.ts | Imports and uses USER_AGENT constant in error message formatting |
| src/rpc-client.ts | Imports and uses USER_AGENT constant in HTTP headers |
| src/requestBuilder.ts | Imports and uses USER_AGENT constant in request headers |
| src/requestBuilder.test.ts | Imports and uses USER_AGENT constant in test assertions |
I've completed my review of this pull request. The refactoring is well-executed with the following observations:
Positive aspects:
- All instances of the hard-coded string have been successfully replaced
- The constant is properly documented with a JSDoc comment
- The constant follows the existing naming conventions in
consts.ts - Test files have been updated to maintain consistency
- The change is purely a refactoring with no behavioral modifications
No issues found: The code changes are clean, consistent, and properly implemented. All files correctly import and use the new constant, and the refactoring achieves its stated goal of improving maintainability.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace hard-coded 'https://api.stackone.com' fallback URL with the DEFAULT_BASE_URL constant from consts.ts for consistency.
Tests should use hard-coded values to properly verify the expected output rather than referencing the same constant being tested.
b6b0fd7 to
930aa61
Compare
Summary
Extracts hard-coded strings into shared constants in
src/consts.tsfor improved maintainability and consistency.What Changed
USER_AGENTconstant and updatedrequestBuilder.ts,rpc-client.ts, andutils/errors.tsto use itrpc-client.tsto use existingDEFAULT_BASE_URLconstant instead of hard-coded fallback URLWhy
Previously, these values were duplicated across multiple files. Centralising them:
consts.ts